package com.cheng.mybatis.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cheng.mybatis.domain.User;
import com.cheng.mybatis.service.UserService;

@Controller
public class LoginController {

	@Autowired
	private UserService UserService;

	/*
	 * @RequestMapping("/login") public String login(User user, HttpSession session)
	 * {
	 * 
	 * 
	 * User user2 = UserService.login(user); if (user2 != null) {
	 * session.setAttribute("user", user2); return "redirect:admin/login/home.jsp";
	 * } return "login.jsp"; }
	 */

	@RequestMapping("/login")
	public String login(User user, HttpSession session) {

		User user2 = UserService.login(user);
		if (user2 != null) {
			session.setAttribute("user", user2);
			return "redirect:login2.action";
		}
		return "redirect:login.jsp";
	}

	@RequestMapping("/login2")
	public String login2() {
		return "admin/login/home.jsp";
	}

}
